<script setup>
import GoBackAndSearchNav from "@/components/GoBackAndSearchNav.vue";
import {useRouter} from 'vue-router'
import { areaList } from '@vant/area-data';
import {saveAddressAPI} from "@/api/address.js";
import 'vant/es/dialog/style'
import {showConfirmDialog} from "vant";

const router = useRouter()

const goBack = () => {
  showConfirmDialog({
    message: '是否确认放弃新增收货地址'
  }).then(() => {
    // on confirm
    router.back()
  }).catch(() => {
    // on cancel
  });
}

const onSave = async (info) => {
  const res = await saveAddressAPI(info)
  if (res) {
    router.back()
  }
}
const onDelete = () => {

}
</script>

<template>
  <div class="address-list">
    <!--<GoBackAndSearchNav :title="'新增收货地址'" :placeholder="true"></GoBackAndSearchNav>-->
    <van-nav-bar :title="'新增收货地址'" left-text="返回" left-arrow fixed @click-left="goBack" placeholder/>
    <van-address-edit
        :area-list="areaList"
        show-set-default
        show-search-result
        tel-maxlength="11"
        :area-columns-placeholder="['请选择', '请选择', '请选择']"
        @save="onSave"
        @delete="onDelete"
    />
  </div>
</template>

<style scoped lang="scss">

</style>